<template>
  <base-breadcrumb>
    <template>
      <div class="table-page-search-wrapper">
        <searchData :searchData="searchArr" @search="search"></searchData>
      </div>
    </template>
    <a-card>
      <div class="table-operator">
        <a-button type="primary" icon="plus" @click="handleAdd" v-btnPermission="'bm_008_add_01'">新增</a-button>
      </div>
      <div class="table-operateors mb20">
        <div class="pub-table-select-count" style="margin: 10px 0">
          <a-icon type="info-circle" theme="twoTone" />
          <span>
            价款(不含税)（万元）：
            <a>{{ from.priceExTax }}</a>
          </span>
          <a-divider type="vertical" />
          <span>
            价款（增值税)( 万元）：
            <a>{{ from.tax }}</a>
          </span>
          <a-divider type="vertical" />
          <span>
            价款(含税)（万元）：
            <a>{{ from.priceContainTax }}</a>
          </span>
        </div>
      </div>

      <list-table ref="table" size="default" rowKey="key" :columns="columns" :request="loadData" :alert="true" show-size-changer show-quick-jumper showPagination="auto">
        <span slot="operation" slot-scope="text, record">
          <MoreButton>
            <a @click="detailed(record)" v-btnPermission="'bm_008_loo_04'">查看</a>
            <span v-if="(record.auditStatus != 'SUBMITTED' && record.auditStatus != 'PAST' && record.auditStatus != 'ABOLISH') && hideBuquBtn()" v-btnPermission="'bm_008_edi_02'">
              <a @click="addEdit(record)">编辑</a>
            </span>
            <span v-if="(record.auditStatus != 'SUBMITTED' && record.auditStatus != 'PAST' && record.auditStatus != 'ABOLISH') && hideBuquBtn()">
              <a @click="deleteDraft(record)">删除</a>
            </span>
            <span v-if="(record.auditStatus == 'SUBMITTED' && userId === record.creatorId) && hideBuquBtn()">
              <a @click="handleUndo({ id: record.id, type: 1 })">撤销</a>
            </span>
            <span v-if="record.auditStatus == 'PAST'&&hideBuquBtn()" v-btnPermission="'bm_008_tov_05'">
              <a @click="handleInvalid({ id: record.id, type: 2 })">作废</a>
            </span>
            <span v-if="record.auditStatus === 'PAST' || record.auditStatus === 'SUBMITTED' || record.auditStatus === 'REJECTED' || record.auditStatus === 'ABOLISH'" v-btnPermission="'bm_008_loo_04'">
              <approval-button :status="record.auditStatus" :id="record.id"></approval-button>
            </span>
          </MoreButton>
        </span>
        <span slot="auditStatus" slot-scope="text, record">
          <list-status :status="record.auditStatus" :isApproval="true" conversion="en" :text="text"></list-status>
        </span>
      </list-table>
    </a-card>
  </base-breadcrumb>
</template>

<script>
import { getList, deteleList, getListCount, cancel } from '@/api/businessAffairs/subcontractingBudget'
import { status } from '@/components/constant'
import SelectSubCompany from '@/components/Select/SelectSubCompany' // 分公司
import SelectProject from '@/components/Select/SelectProject' // 分公司
import OrgTreeSelect from '@/components/OrgTreeSelect'
import SelectSubcontractorCode from '@/components/Select/SelectSubcontractorCode' // 分包商
import { STable } from '@/components'
import BasePage from '@/views/basePage' // 基础配置
const columns = [
  {
    title: '分包单位名称',
    dataIndex: 'subContractUnitName'
  },
  {
    title: '所属分公司',
    dataIndex: 'branchComName'
  },
  {
    title: '所属项目',
    dataIndex: 'projectName'
  },
  {
    title: '预算价款（不含税）( 万元）',
    dataIndex: 'excludeTaxAmount'
  },
  {
    title: '预算价款（增值税）( 万元）',
    dataIndex: 'taxAmount'
  },
  {
    title: '预算价款（含税）（万元）',
    dataIndex: 'amount'
  },
  {
    title: '开工日期',
    dataIndex: 'workStartDate'
  },
  {
    title: '完工日期',
    dataIndex: 'workEndDate'
  },
  {
    title: '填报人',
    dataIndex: 'creatorName'
  },
  {
    title: '填报时间',
    dataIndex: 'createTime'
  },
  {
    title: '状态',
    dataIndex: 'auditStatus',
    scopedSlots: { customRender: 'auditStatus' }
  },
  {
    title: '操作',
    dataIndex: 'operation',
    width: '170px',
    scopedSlots: { customRender: 'operation' }
  }
]

const searchArr = [
  {
    name: '所属单位',
    valueKey: 'searchQuery',
    type: OrgTreeSelect,
  },
  // {
  //   name: '所属分公司',
  //   valueKey: 'branchComId',
  //   type: SelectSubCompany
  // },
  // {
  //   name: '所属项目',
  //   keyValue: 'branchComId',
  //   valueKey: 'projectId',
  //   type: SelectProject
  // },
  { name: '分包商', type: 'input', value: 'subContractUnitName' },
  // {
  //     name: '分包商',
  //     keyValue: 'projectId',
  //     valueKey: 'subContractorId',
  //     type: SelectSubcontractorCode
  // },
  {
    name: '开工日期',
    value: 'workStart',
    type: 'dateRange'
  },
  {
    name: '完工日期',
    value: 'workEnd',
    type: 'dateRange'
  },

  {
    name: '填报人',
    value: 'creatorName',
    type: 'input'
  },
  {
    name: '填报时间',
    value: 'startEndDate',
    type: 'dateRange'
  },
  {
    name: '状态',
    value: 'auditStatus',
    type: 'select',
    data: typeListApproval
  }
]
import { typeListApproval } from '@/utils/util'
export default {
  name: 'a' + Date.now(),
  extends: new BasePage(),
  components: {
    STable
  },
  data() {
    this.columns = columns
    this.searchArr = searchArr
    return {
      queryParam: {},
      from: {},
      userId: JSON.parse(sessionStorage.getItem('ycloud-user_info')).id,
      loadData: (parameter) => {
        const requestParameters = Object.assign({}, parameter, this.queryParam)

        if (this.queryParam.startEndDate?.length > 0) {
          requestParameters.createTimeBegin = this.queryParam.startEndDate[0].format('YYYY-MM-DD HH:mm:ss') || void 0
          requestParameters.createTimeEnd = this.queryParam.startEndDate[1].format('YYYY-MM-DD HH:mm:ss') || void 0
        }
        console.log(this.queryParam.workStart)
        if (this.queryParam.workStart?.length > 0) {
          requestParameters.workStartDateBegin = this.queryParam.workStart[0].format('YYYY-MM-DD HH:mm:ss') || void 0
          requestParameters.workStartDateEnd = this.queryParam.workStart[1].format('YYYY-MM-DD HH:mm:ss') || void 0
        }
        if (this.queryParam.workEnd?.length > 0) {
          requestParameters.workEndDateBegin = this.queryParam.workEnd[0].format('YYYY-MM-DD HH:mm:ss') || void 0
          requestParameters.workEndDateEnd = this.queryParam.workEnd[1].format('YYYY-MM-DD HH:mm:ss') || void 0
        }
        this.getListCount(requestParameters)
        return getList(requestParameters).then((res) => {
          console.log('数据返回对象：', res)
          return res
        })
      },
      removeApi: { invalid: cancel, undo: cancel } // api
    }
  },
  created() {},
  methods: {
    //搜索
    search(value) {
      console.log(value)
      this.queryParam = value
      this.$refs.table.refresh(true)
    },
    getListCount(requestParameters) {
      getListCount(requestParameters).then((res) => {
        this.from = res.data
      })
    },
    // 删除草稿
    deleteDraft(e) {
      let that = this
      that.$confirm({
        title: '温馨提示',
        content: '确定是否删除数据？',
        okText: '确认',
        okType: 'danger',
        cancelText: '取消',
        onOk() {
          console.log(e)
          return deteleList({ id: e.id })
            .then((res) => {
              that.$message.success('删除成功！')
              that.$refs.table.refresh(true)
            })
            .catch((res) => {
              that.$message.warning('删除失败！')
            })
        }
      })
    },
    handleManage() {},
    //新增
    handleAdd() {
      this.$router.push('/businessAffairs/constructionBudget/subcontractingBudget/newIncrease')
    },
    // 查看
    detailed(e) {
      this.$router.push({
        path: '/businessAffairs/constructionBudget/subcontractingBudget/newIncrease',
        query: { id: e.id, type: 'view' }
      })
    },
    //编辑
    addEdit(e) {
      this.$router.push({
        path: '/businessAffairs/constructionBudget/subcontractingBudget/newIncrease',
        query: { id: e.id },
        type: 'edit'
      })
    }
  }
}
</script>

<style lang="less">
.not-submit {
  display: inline-block;
  padding: 0;
  li {
    list-style: disc;
    color: red;
  }
}
.submitted {
  display: inline-block;
  padding: 0;
  li {
    list-style: disc;
    color: green;
  }
}
</style>
